package com.kch.system.service.impl;

import com.kch.system.domain.SysMemberVoice;
import com.kch.system.mapper.SysMemberVoiceMapper;
import com.kch.system.service.ISysMemberVoiceService;
import com.kch.system.vo.SysMemberVoiceVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysMemberVoiceServiceImpl implements ISysMemberVoiceService {

    @Autowired
    public SysMemberVoiceMapper sysMemberVoiceMapper;

    @Override
    public List<SysMemberVoiceVO> selectMemberVoicePage(SysMemberVoiceVO sysMemberVoice) {
        return sysMemberVoiceMapper.selectMemberVoicePage(sysMemberVoice);
    }

    @Override
    public int insetSysMemberVoice(SysMemberVoice sysMemberVoice) {
        return sysMemberVoiceMapper.insert(sysMemberVoice);
    }

    @Override
    public int deleteMemberVoice(String ids) {
        return sysMemberVoiceMapper.deleteByPrimaryKey(Integer.valueOf(ids));
    }

    @Override
    public SysMemberVoiceVO selectById(Integer id) {
        SysMemberVoice sysMemberVoice = sysMemberVoiceMapper.selectByPrimaryKey(id);
        SysMemberVoiceVO sysMemberVoiceVO = new SysMemberVoiceVO();
        BeanUtils.copyProperties(sysMemberVoice, sysMemberVoiceVO);
        sysMemberVoiceVO.setImageurl(sysMemberVoice.getImg());
        return sysMemberVoiceVO;
    }

    @Override
    public int updateById(SysMemberVoiceVO memberVoice) {
        SysMemberVoice exist = sysMemberVoiceMapper.selectByPrimaryKey(memberVoice.getId());
        memberVoice.setCreateTime(exist.getCreateTime());
        memberVoice.setCreateBy(exist.getCreateBy());
        memberVoice.setStatus(exist.getStatus());
        memberVoice.setUserId(exist.getUserId());
        memberVoice.setReviewStatus(exist.getReviewStatus());
        BeanUtils.copyProperties(memberVoice, exist);
        exist.setImg(memberVoice.getImageurl());
        return sysMemberVoiceMapper.updateByPrimaryKeyWithBLOBs(exist);
    }

    @Override
    public SysMemberVoice selectSysMemberById(Integer id) {
        return sysMemberVoiceMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateSysMemberById(SysMemberVoice memberVoice) {
        return sysMemberVoiceMapper.updateByPrimaryKeyWithBLOBs(memberVoice);
    }

    @Override
    public int updateStatus(Integer id) {
        SysMemberVoice sysMember = sysMemberVoiceMapper.selectByPrimaryKey(id);
        String status = ("0".equals(sysMember.getStatus())? "1" : "0");
        return sysMemberVoiceMapper.updateStatus(id, status);
    }
}
